using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;

/// <summary>
/// Summary description for BaiBaoDAO
/// </summary>
public class BaiBaoDAO:DataProvider
{
    public ArrayList LayMang_BaiBao()
    {
        connect();
        ArrayList arr = new ArrayList();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Select_BaiBao", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                BaiBaoDTO bbdto = new BaiBaoDTO();
                bbdto.MaBaiBao = dr.GetInt32(0);
                bbdto.TenBaiBao = dr.GetString(1);
                bbdto.TenHoiNghi = dr.GetString(2);
                bbdto.Ngay = dr.GetDateTime(3);
                bbdto.LoaiBaiBao = dr.GetInt32(4);
                bbdto.GhiChu = dr.GetString(5);
                arr.Add(bbdto);
            }


        }
        catch (Exception es)
        {
            throw es;
        }
        return arr;
    }
    public void insert(BaiBaoDTO bbdto)
    {
        connect();
        
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Insert_BaiBao", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@tenbb", SqlDbType.NVarChar);
            cmd.Parameters["@tenbb"].Value = bbdto.TenBaiBao.ToString();
            cmd.Parameters["@tenbb"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@tenhoinghi", SqlDbType.NVarChar);
            cmd.Parameters["@tenhoinghi"].Value = bbdto.TenHoiNghi.ToString();
            cmd.Parameters["@tenhoinghi"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@ngay", SqlDbType.SmallDateTime);
            cmd.Parameters["@ngay"].Value = bbdto.Ngay.ToString();
            cmd.Parameters["@ngay"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@loaibb", SqlDbType.Int);
            cmd.Parameters["@loaibb"].Value = bbdto.LoaiBaiBao;
            cmd.Parameters["@loaibb"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@ghichu", SqlDbType.NVarChar);
            cmd.Parameters["@ghichu"].Value = bbdto.GhiChu;
            cmd.Parameters["@ghichu"].Direction = ParameterDirection.Input;
                        
            cmd.ExecuteNonQuery();            
        }
        catch (Exception es)
        {
            throw es;
        }        
    }
    
	public BaiBaoDAO()
	{
		//
		// TODO: Add constructor logic here
		//
	}
}
